package sicnu.cs.aps.rest;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import sicnu.cs.aps.common.ResultInfo;
import sicnu.cs.aps.common.ResultInfoUtil;
import sicnu.cs.aps.domain.form.ActivityTeamQueryForm;
import sicnu.cs.aps.domain.vo.TeamInfoVo;
import sicnu.cs.aps.service.IActivityTeamService;
import sicnu.cs.aps.service.IUserService;

import javax.validation.Valid;


/**
 * description 小队信息接口
 *
 * @author chenhetao
 * @version 1.0
 * @className TeamResource
 * @packageName sicnu.cs.aps.rest
 * @date 2022/6/2 14:46
 */
@Slf4j
@RestController
@RequestMapping("/team")
@RequiredArgsConstructor
@Api(tags = {"小队模块"})
public class TeamResource {

    private final IActivityTeamService teamService;
    private final IUserService userService;

    @ApiOperation("查询单个小队详细信息")
    @GetMapping("/{id}")
    public ResultInfo<TeamInfoVo> getById(@PathVariable("id") Long id){
        //权限限制 service 内

        //查询小队信息
        TeamInfoVo teamInfoVo = teamService.getTeamDetailById(id);
        //返回前端
        return ResultInfoUtil.buildSuccess(teamInfoVo);
    }

    @ApiOperation("查询小队列表")
    @GetMapping("/list")
    public ResultInfo<PageInfo<TeamInfoVo>> getList(@Valid ActivityTeamQueryForm teamQueryForm) {
        //查询小队信息
        //内部进行权限控制
        PageInfo<TeamInfoVo> teamInfoVos = teamService.listTeamDetailByForm(teamQueryForm);
        //返回前端
        return ResultInfoUtil.buildSuccess(teamInfoVos);
    }
}
